{% extends "templates/atnet_base.html" %}

{% block csslink %}
{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$('#lot_owners').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": true,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
   		"bProcessing": true,
   		"sAjaxSource": "{{ uri_for('creation_coowners', imm_id=immeuble.key().id(), command='list_json') }}",
   		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
   			$('td:eq(4)', nRow).html('<nobr><a href="javascript:void(0);" id="' + aData[4] + '" class="edit">{{ _("Edit") }}</a>&nbsp;<a href="javascript:void(0);" id="' + aData[4] + '" class="add_to_council">{{ _("Add to council") }}</a></nobr>');
   		},
	});
	
	$('#lot_owners tbody tr a').live('click', function(e) {
		if ($(this).attr('class') == 'edit') {
			$(this).LaunchPopup(
					{
						TableId: '#lot_owners',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('vie_contacts', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: '{{ _("Edit contact") }}',
					})
		}
		if ($(this).attr('class') == 'add_to_council') {
			$(this).LaunchPopup(
					{
						TableId: '#council',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('creation_council', imm_id=immeuble.key().id(), command='add_to_council') }}" + e.target.id + "/",
						Mode: 'add',
						Title: '{{ _("Add to council") }}',
					})
		}
	});
	
	$('#council').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": true,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
   		"bProcessing": true,
   		"sAjaxSource": "{{ uri_for('creation_council', imm_id=immeuble.key().id(), command='list_json') }}",
   		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
   			$('td:eq(2)', nRow).html('<a href="javascript:void(0);" id="' + aData[2] + '" class="delete">{{ _("Delete") }}</a>');
   		},
	});
	
	$('#add-coowner-person').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#lot_owners',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('creation_coowners',imm_id=app_user.last_active_immeuble_id, command='add_person') }}",
				Mode: 'add',
				Title: '{{ _("Add owner (person)") }}',
			}
		)
	});
	
	$('#add-coowner-company').live('click', function(){
		$(this).LaunchPopup(
		{
			TableId: '#lot_owners',
			DivId: '#dialog-form',
			FormId: '#generated-form',
			UrlForm: "{{ uri_for('creation_coowners',imm_id=app_user.last_active_immeuble_id, command='add_company') }}",
			Mode: 'add',
			Title: '{{ _("Add owner (company)") }}',
		}
	)
	});

	$('#add-to-council').live('click', function(){
		$(this).LaunchPopup(
		{
			TableId: '#council',
			DivId: '#dialog-form',
			FormId: '#generated-form',
			UrlForm: "{{ uri_for('creation_council',imm_id=app_user.last_active_immeuble_id, command='add') }}",
			Mode: 'add',
			Title: '{{ _("Add to council") }}',
		}
		)
	});
	
	$('#council tbody tr a').live('click', function(e) {
		if ($(this).attr('class') == 'edit') {
			$(this).LaunchPopup(
					{
						TableId: '#council',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('creation_council', imm_id=app_user.last_active_immeuble_id, command='edit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: '{{ _("Edit") }}',
					}
				)
		}
		if ($(this).attr('class') == 'delete') {
			$(this).LaunchPopup(
					{
						TableId: '#council',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('creation_council', imm_id=app_user.last_active_immeuble_id, command='delete') }}" + e.target.id + "/",
						Mode: 'delete',
						Title: '{{ _("Delete from council") }}',
					}
				)
		}
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{{ super() }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_creation_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	<div id="demo">
    <fieldset>
    <legend>{{ _('Coowners')}}</legend>
    	<div>
		<a href="javascript:void(0);" id="add-coowner-person">{{ _('Add owner (person)') }}</a> ||
		<a href="javascript:void(0);" id="add-coowner-company">{{ _('Add owner (company)') }}</a>
	</div>
    
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="lot_owners" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.owner)}}</th>
				<th>{{ _(fields.default_email)}}</th>
				<th>{{ _(fields.default_phone)}}</th>
				<th>{{ _(fields.address)}}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.owner)}}</th>
				<th>{{ _(fields.default_email)}}</th>
				<th>{{ _(fields.default_phone)}}</th>
				<th>{{ _(fields.address)}}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</fieldset>
	</div>
	<br/><br/>
	<div>
	<fieldset>
    <legend>{{ _('Fines')}}</legend>
	<form method="POST" action="">
		<div class="div-table">		
			{% if ok_message != "" %}
				<div class="div-table-row">
					<div class="div-table-col-header">
					</div>
					<div class="div-table-col">
						<div class="ok">{{ ok_message }}</div>
					</div>
				</div>
			{% endif %}
			{% for field in frais_form %}
				<div class="div-table-row">
					<div class="div-table-col-header">
						{% if fields %}{{ _(fields[field.name]) }}{% else %}{{ field.label.text }}{% endif %}{% if "required" in field.flags %}<div class="error" style="display: inline;">*</div>{% endif %}:
					</div>
					<div class="div-table-col">
						{{ field }}
						{% if field.errors %}
							{% for error in field.errors %}
								<li class="error">{{error}}</li>
							{% endfor %}
						{% endif %}
					</div>
				</div>
			{% endfor %}
		</div>
		<div class="submit" style="padding: 10px">
			<input type="submit" value="Save" class="submitbutton" >
		</div>
	</form>
	</fieldset>
	</div>
	<br/>
	<br/>
	<div>
    <fieldset>
    <legend>{{ _('Syndic council')}}</legend>
    <p><a href="javascript:void(0);" id="add-to-council">{{ _('Add to council') }}</a></p>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="council" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.lot_owner)}}</th>
				<th>{{ _(fields.function)}}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.lot_owner)}}</th>
				<th>{{ _(fields.function)}}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</fieldset>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>
{% endblock %}
